#pragma once

#include <iostream>
#include <vector>

using namespace std;

struct ListNode
{
    int val;
    ListNode* next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int val) : val(val), next(nullptr) {}
    ListNode(int val, ListNode* next) : val(val), next(next) {}
};

ListNode* createLinkedList(const vector<int>& nums)
{
    if (nums.empty()) return nullptr;
    
    ListNode* dummy = new ListNode(-1);
    ListNode* cur = dummy;
    
    for (int num : nums)
    {
        cur->next = new ListNode(num);
        cur = cur->next;
    }
    
    ListNode* head = dummy->next;
    delete dummy;
    return head;
}

void printLinkedList(ListNode* head)
{
    if (!head)
    {
        cout << "空链表" << endl;
        return;
    }
    
    ListNode* cur = head;
    while (cur)
    {
        cout << cur->val;
        if (cur->next)
            cout << " -> ";
        else
            cout << " -> nullptr";
        cur = cur->next;
    }
    cout << endl;
}